package thread;

/**
 * 演示线程的优先级
 */
public class PriorityDemo {
    public static void main(String[] args) {
        //
        Thread normal = new Thread(() -> {
            for (int i = 0; i < 100; i++) {
                System.out.println("normal:" + i);
            }
        });

        Thread max = new Thread(() -> {
            for (int i = 0; i < 100; i++) {
                System.out.println("max:" + i);
            }
        });

        Thread min = new Thread(() -> {
            for (int i = 0; i < 100; i++) {
                System.out.println("min:" + i);
            }
        });

        // 由于现在的cpu的核数是多核的，所以，优先级这个概念就显得有些鸡肋了。
        // 但是如果是单核的cpu，那么优先级高的线程，会比优先级低的线程先执行。
        max.setPriority(Thread.MAX_PRIORITY);
        min.setPriority(Thread.MIN_PRIORITY);
        normal.start();
        max.start();
        min.start();


    }
}


